<?php

namespace app\model\api;

use laytp\BaseModel;
use Phinx\Db\Table;
use think\Db;

class MiniMount extends BaseModel
{
    /**
     * 坐骑
     * @param $record_id
     * @return MiniMount|array|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getMountInfo($record_id)
    {
        return $this->where('record_id', $record_id)->cache(true)->find();
    }

    /**
     * 升级坐骑
     * @param $mount_id
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function upgradeMount($mount_id)
    {
        $upgrade = $this->where('p_id', $mount_id)->select()->toArray();
        foreach ($upgrade as &$item){
            $item['skill'] = json_decode($item['skill'],true);
            $recordInfo = $this->table('lt_mini_record')->where('id',$item['record_id'])->find()->toArray();
            $item['primary_type'] = $recordInfo['primary_type'];
            $item['second_type'] = $recordInfo['second_type'];
            $item['name'] = $recordInfo['name'];
            $item['img_url'] = $recordInfo['img_url'];
        }
        return $upgrade;
    }
}